-- CALC_CAVE_14_TARGET_CLASS

-- 计算野猪巢穴的中心格子类型
return function()
    local dungeonId = DungeonM.getDungeonId();

    -- 无尽，这要只要main
    if DungeonAreaM.query(dungeonId, "type") == "main" then
        -- 巫师残骸29层保底出现
        local layer = DungeonM.currentLayer();
        if layer == 29 and DungeonInstanceM.getInstanceStat(84) <= 0 then
            return 84;
        end

        -- 冒险者残骸
        if DungeonInstanceM.getInstanceStat(45) <= 0 then
            return 45;
        end
    end

    local arr = {
        { ["class"] = 45, ["ratio"] = 60, ["only"] = 0, }, -- 冒险者残骸
        { ["class"] = 41, ["ratio"] = 30, ["only"] = 0, }, -- 果树
        { ["class"] = 58, ["ratio"] = 15, ["only"] = 1, }, -- 奇怪的盾牌
        { ["class"] = 83, ["ratio"] = 15, ["only"] = 1, }, -- 奇怪的兔子
        { ["class"] = 84, ["ratio"] = 30, ["only"] = 1, }, -- 巫师的残骸
    };

    local map;
    for _, map in pairs(arr) do
        if map["only"] == 1 then
            if DungeonInstanceM.getInstanceStat(map["class"]) > 0 then
                map["ratio"] = 0;
            end

            if type(dungeonId) == "number" and dungeonId > 0 and
               DungeonAreaM.query(dungeonId, "type") == "child" then
                map["ratio"] = 0;
            end
        end
    end

    -- 先过滤一遍
    DungeonInstanceM.filterInstanceGrids(arr);

    local seed = DungeonM.getRandSeed("CALC_CAVE_14_TARGET_CLASS");
    local info = fetchElemBySeed(arr, seed);

    return info["class"];
end
